    //
//  articleViewControl.m
//  NewsReaderPhone
//
//  Created by lang langhonglin on 10-8-17.
//  Copyright 2010 hgzp. All rights reserved.
//

#import "articleViewControl.h"


@implementation articleViewControl

@synthesize webView,urlString,navBar,toolBar;

/*
 // The designated initializer.  Override if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad.
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    if ((self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil])) {
        // Custom initialization
    }
    return self;
}
*/

/*
// Implement loadView to create a view hierarchy programmatically, without using a nib.
- (void)loadView {
}
*/


// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
    [super viewDidLoad];
	
	NSString *path = urlString;
    NSURL *url = [NSURL URLWithString:path];
	webView.delegate = self;
    [webView loadRequest:[NSURLRequest requestWithURL:url]];
	
}



- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Overriden to allow any orientation.
    return YES;
}


- (void)didReceiveMemoryWarning {
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
    
    // Release any cached data, images, etc that aren't in use.
}


-(IBAction) closeArticleView {

	[[self parentViewController] dismissModalViewControllerAnimated:YES];
}

-(IBAction) reloadArticleView {
	
	//[webView reload];
	[[self parentViewController] dismissModalViewControllerAnimated:YES];
	
}


-(IBAction) saveArticleView {
	
	
}

-(void)  setUrlString:(NSString *)str {
	
	urlString = str;
}

-(void) LoadUrlString:(NSString *)str {
	
	NSString *path = str;
    NSURL *url = [NSURL URLWithString:path];
    [webView loadRequest:[NSURLRequest requestWithURL:url]];
	
}


//放大
-(IBAction) Enlarge {
	
	[ webView stringByEvaluatingJavaScriptFromString:@"elf()"];
	
}

//缩小
-(IBAction) Narrow {
	
   [ webView stringByEvaluatingJavaScriptFromString:@"slf()"];	
}

//更多文章
-(IBAction) MoreArticle {
	
	[ webView stringByEvaluatingJavaScriptFromString:@"shownavban()"];

}

//返回
-(IBAction) BankView {
	
	[ webView goBack];
}

- (void)viewDidUnload {
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

-(IBAction) AddFavorite {
	
	[ webView stringByEvaluatingJavaScriptFromString:@"AddFavorite()"];

}

-(IBAction) MoveDown {
	

	int scrollPosition = [[webView stringByEvaluatingJavaScriptFromString:@"window.pageYOffset"] intValue];
	scrollPosition += 30;
	[webView stringByEvaluatingJavaScriptFromString: [NSString stringWithFormat:@"window.scrollBy(0,%d);",scrollPosition]];
}

-(IBAction) MoveUp {
	
	int scrollPosition = [[webView stringByEvaluatingJavaScriptFromString:@"window.pageYOffset"] intValue];
	scrollPosition -= 30;
	[webView stringByEvaluatingJavaScriptFromString: [NSString stringWithFormat:@"window.scrollBy(0,%d);",scrollPosition]];
	
	
}

- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {

	NSURL *url = request.URL;
	NSString *urlString = url.absoluteString;
	
//	NSLog(urlString);
	if( [urlString rangeOfString:@"mindex.aspx"].length > 0  )
	{
		[[self parentViewController] dismissModalViewControllerAnimated:YES];
		return NO;
	}
	
	if ([urlString rangeOfString:@"login.aspx"].length > 0 
		|| [urlString rangeOfString:@"register.aspx"].length > 0 
		|| [urlString rangeOfString:@"MSubCenter.aspx"].length > 0
		|| [urlString rangeOfString:@"mpaperorder.aspx"].length > 0 
		|| [urlString rangeOfString:@"mPayOrder.aspx"].length > 0 
		|| [urlString rangeOfString:@"mUserCharge.aspx"].length > 0 
		|| [urlString rangeOfString:@"mcounter.aspx"].length > 0  )
	{
		webView.scalesPageToFit = NO;
		navBar.hidden = NO;
		toolBar.hidden = NO;
		return YES;
		
	}
	else
	{
	    webView.scalesPageToFit = YES;
		navBar.hidden = YES;
		toolBar.hidden = YES;
		return  YES;
	}
	return YES;
}




- (void)dealloc {
    [super dealloc];
}


@end
